
#HLA EPITOPES FREQUENCY DATABASE
#Function: Insert data into [epit_pospoly] table [EpitHLA] schema
#Created in: 29.01.2014
#Author: Louise Takeshita

use strict;
use EpiPolyHash qw(epi_poly);

#Process Epitope data into HashMap
my %epi_poly = epi_poly; # returns hashmap

#Create output file
open(OUTPUT,">insert_epitpospoly.sql") || die "The file insert_epitpospoly.sql could not be opened.\n"; #open file and handle unexpected errors

#Processing
foreach my $ep(sort {$epi_poly{$a}{'id'} <=> $epi_poly{$b}{'id'}} keys %epi_poly)
	{
	my $epit_id = $epi_poly{$ep}{'id'};
	foreach my $pos(sort {$a <=> $b} keys $epi_poly{$ep}{'poly'})
		{
		my $poly = $epi_poly{$ep}{'poly'}{$pos};
		print OUTPUT "INSERT INTO EpitHLA.epit_pospoly VALUES ($epit_id,'$pos','$poly');\n";
		}
	}

print "Done!";	
